package com.kdg.passwordgenerator;

import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * User: Adrynalyne
 * Date: 9/14/13
 * Time: 9:50 PM
 * To change this template use File | Settings | File Templates.
 */
@SuppressWarnings("DefaultFileTemplate")
class Generator {

    private static final String AB = "ABCDEFGHIJKLMNOPQRSTUVWXYZacbdefghijklmnopqrstuvwxyz";
    private static final String symbols = "`~!@#$%^&*()-_=+{}[]:;'?.>,<|";
    private final Random random = new Random();


    public String poolCharacters(int length, String type) {
        StringBuilder sb = new StringBuilder(length);
        StringBuilder sb2 = new StringBuilder(length);


            if ( type.equals("l") || (type.equals("n")) || (type.equals("s"))) {
                for (int i = 0; i < length; i++) {
                if (type.equals("l")) {
                    sb.append(AB.charAt(random.nextInt(AB.length())));

                } else if (type.equals("n")) {
                    sb.append(random.nextInt(10));

                } else {
                    sb.append(symbols.charAt(random.nextInt(symbols.length())));

                }
                }

                return sb.toString();

            } else if (type.equals("ls") || (type.equals("ln")) || (type.equals("ns"))) {
                for (int c = 0; c < length; c++) {
                if (type.equals("ls")) {
                    sb.append(AB.charAt(random.nextInt(AB.length())));
                    sb.append(symbols.charAt(random.nextInt(symbols.length())));
                    sb2.append(sb.charAt(random.nextInt(sb.length())));

                } else if (type.equals("ln")) {
                    sb.append(AB.charAt(random.nextInt(AB.length())));
                    sb.append(random.nextInt(10));
                    sb2.append(sb.charAt(random.nextInt(sb.length())));

                } else {
                    sb.append(symbols.charAt(random.nextInt(symbols.length())));
                    sb.append(random.nextInt(10));
                    sb2.append(sb.charAt(random.nextInt(sb.length())));

                }
                }
                return sb2.toString();

            } else {
                for (int c = 0; c < length; c++) {
                sb.append(symbols.charAt(random.nextInt(symbols.length())));
                sb.append(random.nextInt(10));
                sb.append(AB.charAt(random.nextInt(AB.length())));
                sb2.append(sb.charAt(random.nextInt(sb.length())));
                }

            }
            return sb2.toString();

        }
}
